import { _decorator, Component, Node, director, DirectorEvent, UIRenderer, ScrollView, Mask, UITransform, math, rect } from 'cc';
import { Main } from './Main';
import { MergeItem } from './MergeItem';
import { MergeRoot } from './MergeRoot';
const { ccclass, property } = _decorator;

@ccclass('MergeRootWithCulling')
export class MergeRootWithCulling extends MergeRoot {

    /**
     * 该节点的AnchorPoint需要跟MergeRootWithCulling的node的AnchorPoint保持一致 
    */
    @property(UITransform)
    cullingNodeTrans: UITransform = null;

    boundingBox: math.Rect;

    onLoad() {
        const rect = this.boundingBox = new math.Rect();
        const uiTrns = this.cullingNodeTrans;
        const contentSize = uiTrns.contentSize;
        const anchorPoint = uiTrns.anchorPoint;
        rect.set(-anchorPoint.x * contentSize.width, -anchorPoint.y * contentSize.height, contentSize.width, contentSize.height)
    }

    checkCulling(comp: { getBoundingBox: Function }) {
        return this.boundingBox.intersects(comp.getBoundingBox());
    }

}


